<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveSupport::Cache</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveSupport::Cache</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache_rb.html">
                vendor/rails/activesupport/lib/active_support/cache.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/compressed_mem_cache_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/compressed_mem_cache_store.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/drb_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/drb_store.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/file_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/file_store.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/mem_cache_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/mem_cache_store.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/memory_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/memory_store.rb
                </a>
        <br />
                <a href="../../files/vendor/rails/activesupport/lib/active_support/cache/synchronized_memory_store_rb.html">
                vendor/rails/activesupport/lib/active_support/cache/synchronized_memory_store.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
See <a href="Cache/Store.html">ActiveSupport::Cache::Store</a> for
documentation.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000321">expand_cache_key</a>&nbsp;&nbsp;
      <a href="#M000320">lookup_store</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="Cache/CompressedMemCacheStore.html" class="link">ActiveSupport::Cache::CompressedMemCacheStore</a><br />
Class <a href="Cache/FileStore.html" class="link">ActiveSupport::Cache::FileStore</a><br />
Class <a href="Cache/MemCacheStore.html" class="link">ActiveSupport::Cache::MemCacheStore</a><br />
Class <a href="Cache/MemoryStore.html" class="link">ActiveSupport::Cache::MemoryStore</a><br />
Class <a href="Cache/Store.html" class="link">ActiveSupport::Cache::Store</a><br />
Class <a href="Cache/SynchronizedMemoryStore.html" class="link">ActiveSupport::Cache::SynchronizedMemoryStore</a><br />

    </div>




      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000321" class="method-detail">
        <a name="M000321"></a>

        <div class="method-heading">
          <a href="#M000321" class="method-signature">
          <span class="method-name">expand_cache_key</span><span class="method-args">(key, namespace = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000321-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000321-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">expand_cache_key</span>(<span class="ruby-identifier">key</span>, <span class="ruby-identifier">namespace</span> = <span class="ruby-keyword kw">nil</span>)
47:       <span class="ruby-identifier">expanded_cache_key</span> = <span class="ruby-identifier">namespace</span> <span class="ruby-value">? </span><span class="ruby-node">&quot;#{namespace}/&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;&quot;</span>
48: 
49:       <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RAILS_CACHE_ID&quot;</span>] <span class="ruby-operator">||</span> <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RAILS_APP_VERSION&quot;</span>]
50:         <span class="ruby-identifier">expanded_cache_key</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{ENV[&quot;RAILS_CACHE_ID&quot;] || ENV[&quot;RAILS_APP_VERSION&quot;]}/&quot;</span>
51:       <span class="ruby-keyword kw">end</span>
52: 
53:       <span class="ruby-identifier">expanded_cache_key</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">case</span>
54:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:cache_key</span>)
55:           <span class="ruby-identifier">key</span>.<span class="ruby-identifier">cache_key</span>
56:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
57:           <span class="ruby-identifier">key</span>.<span class="ruby-identifier">collect</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span> <span class="ruby-identifier">expand_cache_key</span>(<span class="ruby-identifier">element</span>) }.<span class="ruby-identifier">to_param</span>
58:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">key</span>
59:           <span class="ruby-identifier">key</span>.<span class="ruby-identifier">to_param</span>
60:         <span class="ruby-keyword kw">end</span>.<span class="ruby-identifier">to_s</span>
61: 
62:       <span class="ruby-identifier">expanded_cache_key</span>
63:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000320" class="method-detail">
        <a name="M000320"></a>

        <div class="method-heading">
          <a href="#M000320" class="method-signature">
          <span class="method-name">lookup_store</span><span class="method-args">(*store_option)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a new CacheStore object according to the given options.
</p>
<p>
If no arguments are passed to this method, then a new <a
href="Cache/MemoryStore.html">ActiveSupport::Cache::MemoryStore</a> object
will be returned.
</p>
<p>
If you pass a Symbol as the first argument, then a corresponding cache
store class under the <a href="Cache.html">ActiveSupport::Cache</a>
namespace will be created. For example:
</p>
<pre>
  ActiveSupport::Cache.lookup_store(:memory_store)
  # =&gt; returns a new ActiveSupport::Cache::MemoryStore object

  ActiveSupport::Cache.lookup_store(:drb_store)
  # =&gt; returns a new ActiveSupport::Cache::DRbStore object
</pre>
<p>
Any additional arguments will be passed to the corresponding cache store
class&#8216;s constructor:
</p>
<pre>
  ActiveSupport::Cache.lookup_store(:file_store, &quot;/tmp/cache&quot;)
  # =&gt; same as: ActiveSupport::Cache::FileStore.new(&quot;/tmp/cache&quot;)
</pre>
<p>
If the first argument is not a Symbol, then it will simply be returned:
</p>
<pre>
  ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
  # =&gt; returns MyOwnCacheStore.new
</pre>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000320-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000320-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/rails/activesupport/lib/active_support/cache.rb, line 31</span>
31:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">lookup_store</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">store_option</span>)
32:       <span class="ruby-identifier">store</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">parameters</span> = <span class="ruby-operator">*</span>([ <span class="ruby-identifier">store_option</span> ].<span class="ruby-identifier">flatten</span>)
33: 
34:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">store</span>
35:       <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Symbol</span>
36:         <span class="ruby-identifier">store_class_name</span> = (<span class="ruby-identifier">store</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:drb_store</span> <span class="ruby-operator">?</span> <span class="ruby-value str">&quot;DRbStore&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">store</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">camelize</span>)
37:         <span class="ruby-identifier">store_class</span> = <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">store_class_name</span>)
38:         <span class="ruby-identifier">store_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">parameters</span>)
39:       <span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>
40:         <span class="ruby-constant">ActiveSupport</span><span class="ruby-operator">::</span><span class="ruby-constant">Cache</span><span class="ruby-operator">::</span><span class="ruby-constant">MemoryStore</span>.<span class="ruby-identifier">new</span>
41:       <span class="ruby-keyword kw">else</span>
42:         <span class="ruby-identifier">store</span>
43:       <span class="ruby-keyword kw">end</span>
44:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>